
#include ".\mcpoint2d.h"

#include <math.h>

McPoint2D::McPoint2D(void)
{
}

McPoint2D::~McPoint2D(void)
{
}

McPoint2D::McPoint2D(double x1, double y1)
{
	x = x1;
	y = y1;
}

McPoint2D::McPoint2D(const McPoint &p)
{
	x = p.X();
	y = p.Y();
}

McPoint2D McPoint2D::operator+(const McPoint2D& p)
{
	McPoint2D newp(x + p.X(), y + p.Y());
	return newp;
}

McPoint2D McPoint2D::operator-(const McPoint2D& p)
{
	McPoint2D newp(x - p.X(), y - p.Y());
	return newp;
}

McPoint2D McPoint2D::operator+=(const McPoint2D& p)
{
	McPoint2D newp(x + p.x, y + p.y);
	return newp;
}
McPoint2D McPoint2D::operator-=(const McPoint2D& p)
{
	McPoint2D newp(x - p.x, y - p.y);
	return newp;
}

McPoint2D McPoint2D::operator*(const double scale)
{
	McPoint2D newp(x * scale, y * scale);
	return newp;
}

McPoint2D McPoint2D::operator/(const double scale)
{
	McPoint2D newp(x / scale, y / scale);
	return newp;
}

McPoint2D& McPoint2D::operator=(const McPoint& p)
{
	if ( this != &p )
	{
		x=p.X();
		y=p.Y();
	}

	return *this;
}

bool McPoint2D::operator==(const McPoint2D& p)
{
	return ((p.x == x) && (p.y == y));
}

ofstream & operator>>(McPoint2D &p, ofstream &strm)
{
	strm.write((char*)&(p.x), sizeof(p.x));
	strm.write((char*)&(p.y), sizeof(p.y));
	
	return strm;
	
}

ifstream & operator<<( McPoint2D &p, ifstream &strm)
{
	strm.read((char*)&(p.x), sizeof(p.x));
	strm.read((char*)&(p.y), sizeof(p.y));

	return strm;
	
}

double McPoint2D::Distance(const McPoint& p) const
{
	double dx = x-p.X();
	double dy = y-p.Y();
	double s = dx * dx + dy * dy;

	return (s<0 ? 0.0 :(double)sqrt(s));
}

double McPoint2D::Azimuth(const McPoint& p) const
{
	return (double)atan2(p.Y()-y,p.X()-x);
}

double McPoint2D::X() const
{
	return x;
}

double McPoint2D::GetX() const
{
	return x;
}

double McPoint2D::Y() const
{
	return y;
}

double McPoint2D::GetY() const
{
	return y;
}

double& McPoint2D::rX()
{
	return x;
}

void McPoint2D::SetX(const double x1)
{
	x = x1;
}

double& McPoint2D::rY()
{
	return y;
}

void McPoint2D::SetY(const double y1)
{
	y = y1;
}

void McPoint2D::Set(const double x1, const double y1)
{
	x = x1;
	y = y1;
}


void McPoint2D::Set(const double x1, const double y1, const double z1)
{
	x = x1;
	y = y1;
}

void McPoint2D::Get(double& x1, double& y1) const
{
	x1 = x;
	y1 = y;
}